package com.vegetable.modules.service.bank.convert;


import cn.hutool.core.collection.CollectionUtil;
import com.vegetable.modules.entity.bank.vo.AliPayTran;
import com.vegetable.modules.entity.bank.vo.WechatPayTran;
import com.vegetable.modules.entity.finance.Transactions;
import org.springframework.beans.BeanUtils;
import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

public class GeneralConverter {

    private final ABCConverter abcConverter = new ABCConverter();

    private final CCBConverter ccbConverter = new CCBConverter();

    private final WFBConverter wfbConverter = new WFBConverter();

    private final SPDConverter spdConverter = new SPDConverter();

    private final PABConverter pabConverter = new PABConverter();

    private final CGBConverter cgbConverter = new CGBConverter();

    private final ICBCConverter icbcConverter = new ICBCConverter();

    private final CiticConverter citicConverter = new CiticConverter();

    private final CMBCConverter cmbcConverter = new CMBCConverter();

    private final BCMConverter bcmConverter = new BCMConverter();

    private final BOCConverter bocConverter = new BOCConverter();

    private final PSBCConverter psbcConverter = new PSBCConverter();

    private final BJRCBConverter bjrcbConverter = new BJRCBConverter();
    private final BOBConverter bobConverter = new BOBConverter();
    private final CZBConverter czbConverter = new CZBConverter();
    private final HNNXConverter hnnxConverter = new HNNXConverter();
    private final JsBankConverter jsBankConverter = new JsBankConverter();
    private final NJCBConverter njcbConverter = new NJCBConverter();
    private final SCRCUConverter scrcuCConverter = new SCRCUConverter();
    private final RCBConverter rdbCoverter = new RCBConverter();
    private final WeiChatConverter wxConverter = new WeiChatConverter();
    private final AliConverter aliConverter = new AliConverter();

    public List<Transactions> parse(String site, String originalJson, MultipartFile file) throws Exception {
        List<Transactions> targetJson = new ArrayList<>();
        switch (site) {
            case "beehive-abc": //农行
                targetJson = abcConverter.convert(file);
                break;
            case "beehive-ccb": //建行
                targetJson = ccbConverter.convert(file);
                break;
//            case "beehive-cmb": //招行
//                targetJson = cmbConverter.convert(originalJson);
//                break;
//            case "beehive-spdb": //浦发
//                targetJson = spdConverter.convert(originalJson);
//                break;
//            case "beehive-pabc": //平安
//                targetJson = pabConverter.convert(originalJson);
//                break;
//            case "beehive-gdb": //广发
//                targetJson = cgbConverter.convert(originalJson);
//                break;
            case "beehive-icbc": //工商
                targetJson = icbcConverter.convert(file);
                break;
//            case "beehive-citicb": //中信
//                targetJson = citicConverter.convert(originalJson);
//                break;
//            case "beehive-cmbc": //民生
//                targetJson = cmbcConverter.convert(originalJson);
//                break;
//            case "beehive-bcm": //交行
//                targetJson = bcmConverter.convert(originalJson);
//                break;
            case "beehive-boc": //中行
                targetJson = bocConverter.convert(file);
                break;
            case "beehive-psbc": //邮储
                targetJson = psbcConverter.convert(file);
                break;
//            case "beehive-czb": // 浙商
//                targetJson = czbConverter.convert(originalJson);
//                break;
//            case "beehive-zyb": // 中原银行
//                targetJson = zybConverter.convert(originalJson);
//                break;
//            case "beehive-jsbank": // 江苏银行
//                targetJson = jsBankConverter.convert(originalJson);
//                break;
//            case "beehive-hnnx": // 海南农信
//                targetJson = hnnxConverter.convert(originalJson);
//                break;
//            case "beehive-bjrcb": // 北京农商行
//                targetJson = bjrcbConverter.convert(originalJson);
//                break;
//            case "beehive-bob": // 北京银行
//                targetJson = bobConverter.convert(originalJson);
//                break;
            case "beehive-wfbc": // 潍坊银行
                targetJson = wfbConverter.convert(file);
                break;
            case "beehive-scrcu": // 农信
                targetJson = rdbCoverter.convert(file);
                break;
            case "beehive-wx": // 微信
                List<WechatPayTran> payTrans = wxConverter.convert(file);
                if(CollectionUtil.isNotEmpty(payTrans)){
                    for(WechatPayTran payTran : payTrans){
                        Transactions tmp = new Transactions();
                        BeanUtils.copyProperties(payTran, tmp);
                        tmp.setTradingType(payTran.convertTradingType());
                        tmp.setChannel("WECHAT");
                        tmp.setStatus("SUCCESS");
//                        tmp.setRawData("");
                        tmp.setTradingNo(Transactions.generateUniqueFlowId(tmp));
                        targetJson.add(tmp);
                    }
                }
                break;
            case "beehive-ali": // 微信
                targetJson = aliConverter.convert(file);
                break;

        }
        return targetJson;
    }
}
